/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.delaphone.flocash.web.action;

import com.delaphone.flocash.service.BankService;
import com.delaphone.flocash.web.service.MailService;
import com.opensymphony.xwork2.Action;

/**
 *
 * @author tamdx
 */
public class RequestActiveBankAction extends BaseAction {

    private MailService mailService;
    private BankService bankService;
    private String message;
    private int bank_id;

    public String index() {
        if (user == null) {
            return Action.ERROR;
        }
        if (getBank_id() == 0) {
            setMessage("Please select a bank account");
            return Action.INPUT;
        }
        try {
            bankService.requestActiveBank(bank_id);

            try {
                mailService.sendMail(user.getEmail(), "Request Active Bank", "Hello " + user.getEmail() + "\nYour account Card will be actived next day!");
                setMessage(getText("user.manage_bank.reqActive"));
            } catch (Exception e) {
                setMessage(getText("user.manage_bank.sendMailFail"));
            }
            return Action.INPUT;
        } catch (Exception ex) {
            return Action.ERROR;
        }
    }

    public BankService getBankService() {
        return bankService;
    }

    public void setBankService(BankService bankService) {
        this.bankService = bankService;
    }

    public MailService getMailService() {
        return mailService;
    }

    public void setMailService(MailService mailService) {
        this.mailService = mailService;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getBank_id() {
        return bank_id;
    }

    public void setBank_id(int bank_id) {
        this.bank_id = bank_id;
    }
}
